﻿using System;

namespace Microsoft.Practices.CompositeUI.EventBroker
{
    /// <summary>
    /// 	Declares an event as an <see cref = "EventTopic" /> publication.
    /// </summary>
    [AttributeUsage(AttributeTargets.Event, AllowMultiple = true)]
    public sealed class EventPublicationAttribute : Attribute
    {
        #region Fields & Properties

        private readonly string _topic;

        /// <summary>
        /// 	The name of the <see cref = "EventTopic" /> the decorated event will publish.
        /// </summary>
        public string Topic
        {
            get
            {
                return _topic;
            }
        }

        private readonly PublicationScope _scope;

        /// <summary>
        /// 	The <see cref = "PublicationScope" /> for the publication.
        /// </summary>
        public PublicationScope Scope
        {
            get
            {
                return _scope;
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// 	Declares an event publication for an <see cref = "EventTopic" /> with the specified topic and 
        /// 	a <c>Global</c> <see cref = "PublicationScope" />.
        /// </summary>
        /// <param name = "topic">The name of the <see cref = "EventTopic" /> the decorated event will publish.</param>
        public EventPublicationAttribute(string topic) : this(topic, PublicationScope.Global)
        {
        }

        /// <summary>
        /// 	Declares an event publication for an <see cref = "EventTopic" /> with the specified topic and
        /// 	<see cref = "PublicationScope" />.
        /// </summary>
        /// <param name = "topic">The name of the <see cref = "EventTopic" /> the event will publish.</param>
        /// <param name = "scope">The scope for the publication.</param>
        public EventPublicationAttribute(string topic, PublicationScope scope)
        {
            _topic = topic;
            _scope = scope;
        }

        #endregion
    }
}